/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       mouse.h
 * Author:     karooolek
 * Created on: 2009-01-05
 *
 **********************************************************************************************************************/

#ifndef MOUSE_H_
#define MOUSE_H_

#include "mousebutton.h"
#include "mouselistener.h"
#include "../common.h"
#include <GL/glut.h>

namespace mGameEngine
{

// Application prototype
namespace System
{
    class Application;
}

namespace Input
{

/**
 * Mouse input control.
 * It catches mouse events and sends them to registered listeners.
 */
class Mouse
{
private:
    // GLUT callbacks
    friend class System::Application;
    static void _glutMouseFunc(int btn, int state, int x, int y);
    static void _glutMouseMotionFunc(int x, int y);

    /**
     * Mouse position
     */
    static Vector3 _mpos;

    /**
     * Mouse buttons
     */
    static uint8 _buttons[8];

    /**
     * Registered mouse listeners
     */
    static List<MouseListener *> _listeners;

    /**
     * Private constructor
     */
    Mouse();

public:
    /**
     * Check if button is pressed down.
     * @param btn mouse button
     * @return true is button is pressed down, false otherwise
     */
    static bool isButtonDown(MouseButton btn);

    /**
     * Get any mouse button that is pressed down.
     * @return mouse button or MOUSE_BTN_NONE
     */
    static MouseButton getAnyButtonDown();

    /**
     * Get mouse pointer position.
     * @return mouse pointer position in window coordinates
     */
    static const Vector3 &getPosition();

    /**
     * Set mouse pointer position.
     * @param position mouse pointer position in window coordinates
     */
    static void setPosition(const Vector3 &position);

    /**
     * Register new mouse listener.
     * @param listener mouse listener
     */
    static void addListener(MouseListener *listener);

    /**
     * Unregister mouse listener.
     * @param listener mouse listener
     */
    static void removeListener(MouseListener *listener);
};

}
}

#endif // MOUSE_H_
